﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CreaMotion.UserControls
{

	public partial class TableItem : UserControl
	{
		public TableItem()
		{
			this.InitializeComponent();
		}

        ObservableCollection<Interfaces.Field> ListFieldsSource;

        #region IsAttached Property
        
        private bool isAttached = false;
        public bool IsAttached
        {
            get
            {
                return isAttached;
            }
            set
            {
                isAttached = value;
                ImgAttach.Visibility = value? Visibility.Visible : Visibility.Hidden;
            }
        }

        #endregion

        #region IsEnable

        private bool _isEnable;
        public bool IsEnable
        {
            get
            {
                return _isEnable;
            }
            set
            {
                _isEnable = value;
                LayoutRoot.Background = value ? Brushes.Transparent : Brushes.Red;
            }
        }

        #endregion
        
        #region Source

        private Interfaces.Table source;
        public Interfaces.Table Source
        {
            get 
            {
                return source;
            }
            set 
            {
                source = value;

                labTableName.Text = value.TableName;
                ListFieldsSource = new ObservableCollection<Interfaces.Field>(value.Fields);

                IsEnable = (from Interfaces.Field field in value.Fields
                            where field.IsPrimaryKey
                            select field).FirstOrDefault() != null ? true : false;

                ListFields.ItemsSource = ListFieldsSource;
            }
        }

        #endregion
    }
}